<template>
	<view>
		<view class="bodyBox-t30">
			<uni-list>
				<view @click="back(item)" class="addrinfo" v-for="(item,index) in list" :index="index" :key="index">
					<uni-list-item class="info" :border="false" :title="item.name+' '+item.phone"
						:note="item.detail" />
					<view class="but" style="display: flex;">
						<text class="butc one" @click.stop="setDefault(item)">{{((item.level==1)?'默认':'设为默认')}}</text>
						<text class="butc two" @click.stop="save(item)">修改</text>
						<text class="butc three" @click.stop="deletes(item)">删除</text>
					</view>
				</view>
			</uni-list>
			<view class="" style="position: fixed;top: 10px;right:10px;color: #5555ff; font-size: 16px;">
				<text style="" @click="save()">增加地址</text>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [

				],
				//进入选择  select
				action: ''
			}
		},
		onLoad(option) {
			this.action = option.action
		},
		onShow() {
			this.getAddr();
		},
		methods: {
			back(addr) {
				console.log(1)
				if (this.action == "select") {
					uni.showLoading({
						mask: true,
						title: '返回中···'
					})
					console.log(addr)
					uni.setStorageSync("addr", addr)
					setTimeout(function() {
						uni.navigateBack()
					}, 500)
				}
			},
			getAddr() {
				this.apis.addrList().then(res => {
					this.list = res
				})
			},
			setDefault(item) {
				this.apis.addrSet({
					id: item.id
				}).then(res => {
					this.getAddr()
				})
			},
			deletes(item) {
				this.apis.addrDel({
					id: item.id
				}).then(res => {
					this.getAddr()
				})
			},
			save(item) {
				var id = 0
				if (item) {
					id = item.id
				}
				uni.navigateTo({
					url: "/pagesOne/addrEdit/addrEdit?id=" + id,
				})
			}
		}
	}
</script>

<style lang="scss">
	.addrinfo {
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-bottom: 1px solid #e5e5e5;
	}

	.info {
		flex: 3;
	}

	.but {
		display: flex;
		justify-content: space-around;
		align-items: center;
		flex: 2;
	}

	.butc {
		margin: 5px;
	}

	.one {
		color: #aa5500;
	}

	.two {
		color: #0055ff;
	}

	.three {
		color: #ff0000;
	}
</style>
